using System.Linq;
using Castle.Windsor;

namespace Pipeline.Middleware.Contractual
{
    public static class UseExtensions
    {
        public static void UseAllMiddleware(this IApplicationBuilder applicationBuilder,IWindsorContainer container)
        {
            var middlewares = container.ResolveAll<IMiddleware>();

            applicationBuilder.UseArrange(middlewares.ToList());
        }

        public static void UseDefaultMiddleware(this IApplicationBuilder applicationBuilder)
        {
            applicationBuilder.Use<DefaultMiddleware>();
        }

        public static void Use<TMiddleware>(this IApplicationBuilder applicationBuilder)
            where TMiddleware:IMiddleware
        {
            var middleware = applicationBuilder.Container.Resolve<TMiddleware>();

            applicationBuilder.Use(middleware);
        }

        

        public static void UseGreeting(this IApplicationBuilder applicationBuilder)
        {
            applicationBuilder.Use<GreetingMiddleware>();
        }
    }
}